package com.zhuchang.self_rpc.test.democoding.nettydubbo.server;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @Author RenPu
 * @Date 2022/2/12 14:42
 * @Version 1.0
 * @Description:
 **/
public class NettyDubboHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("客户端发来的消息：msg="+msg);
        if(msg.toString().startsWith("HelloService#hello#")){
            String result = new HelloServiceImpl().hello(msg.toString().substring((msg.toString().indexOf("#"))));
            ctx.writeAndFlush(result);
        }

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.out.println("异常原因："+cause.getMessage());
        ctx.close();
     }
}
